package com.atguigu.gmall.order.controller;

import com.atguigu.gmall.common.cache.GmallCache1;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.util.AuthContextHolder;
import com.atguigu.gmall.model.order.OrderDetail;
import com.atguigu.gmall.model.order.OrderInfo;
import com.atguigu.gmall.model.user.UserAddress;
import com.atguigu.gmall.order.service.OrderService;
import com.atguigu.gmall.user.client.UserFeignClient;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 订单相关的controller控制层
 * @author 搭忆长安
 * @version 1.0
 * @date 2021年07月10日 16:36
 * @ClassName:OrderApiController
 * @Description: TODO
 */
@RestController
@RequestMapping(value = "/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 新增订单
     * @param orderInfo
     * @return
     */
    @GmallCache1
    @PostMapping("/addOrder")
    public Result<OrderInfo> addOrder(@RequestBody OrderInfo orderInfo){
        //获取用户id
        orderInfo.setUserId(1L);
        return  Result.ok(orderService.addOrderInfo(orderInfo));
    }

    /***
     *查询订单信息
     * @param id
     * @return
     */
    @GetMapping("/getById/{id}")
    public OrderInfo getById(@PathVariable("id")Long id){
        return orderService.getById(id);
    }

    /***
     *取消订单
     * @param id
     * @return
     */
    @GetMapping("/cancleOrder/{id}")
    public Result cancleOrder(@PathVariable("id")Long id){
         orderService.cancleOrder(id);
        return Result.ok();
    }

}
